import sys


from playwright.sync_api import sync_playwright
import  time
def run(playwright):
    browser = playwright.chromium.launch(headless=True)
    # context = browser.new_context(record_video_dir="d://")
    context = browser.new_context()
    # Open new page
    page = context.new_page()

    # Go to https://passport.lessonplan.cn/?returnURL=www.lessonplan.cn/
    page.goto("https://passport.lessonplan.cn/?returnURL=www.lessonplan.cn/")

    # Click [placeholder="电话 / 电子邮箱"]
    page.click("[placeholder=\"电话 / 电子邮箱\"]")

    # Fill [placeholder="电话 / 电子邮箱"]
    page.fill("[placeholder=\"电话 / 电子邮箱\"]", "sunwu")

    # Press Tab
    page.press("[placeholder=\"电话 / 电子邮箱\"]", "Tab")

    # Fill [placeholder="密码"]
    page.fill("[placeholder=\"密码\"]", "sunwu123")

    # Click text=登 录
    page.click("text=登 录")

    # Go to https://www.lessonplan.cn/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyR3VpZCI6ImYyNjYwZWNhLTZkNDctMTZjZC01Y2ZlLTQ0NjYyZjVkNzVkMiIsInR5cGUiOiJ0ZWFjaGVyIiwiaWF0IjoxNjMzOTU5MDk4LCJleHAiOjE2MzM5OTUwOTh9.LvZ1OHkkdvvnfkbG74ngrOnnVK8ogigHud-hpqvcBy8
    page.goto("https://www.lessonplan.cn/?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyR3VpZCI6ImYyNjYwZWNhLTZkNDctMTZjZC01Y2ZlLTQ0NjYyZjVkNzVkMiIsInR5cGUiOiJ0ZWFjaGVyIiwiaWF0IjoxNjMzOTU5MDk4LCJleHAiOjE2MzM5OTUwOTh9.LvZ1OHkkdvvnfkbG74ngrOnnVK8ogigHud-hpqvcBy8")

    # Make sure to close, so that videos are saved.
    text = page.inner_text("#content > home-root > my-packet-root > div > div > div.router-content.ng-tns-c79-0.ng-trigger.ng-trigger-fadeIn > packet-file-root > div > div.my-plan-list.ng-tns-c142-1.ng-trigger.ng-trigger-fadeIn.ng-star-inserted > div.my-plan-box.list-table.ng-tns-c142-1.ng-star-inserted > table > thead > tr > th.table-right.ng-tns-c142-1")
    # print(text)
    a=page.is_visible('#content > home-root > my-packet-root > div > div > div.router-content.ng-tns-c79-0.ng-trigger.ng-trigger-fadeIn > packet-file-root > div > div.my-plan-list.ng-tns-c142-1.ng-trigger.ng-trigger-fadeIn.ng-star-inserted > div.my-plan-box.list-table.ng-tns-c142-1.ng-star-inserted > table > thead > tr > th.table-right.ng-tns-c142-1')
    print(a)
    print(text)
    assert text=='课程包信息'
    if(text=='课程包信息'):
        sys.exit(0)
    else:
        sys.exit(1)
    # print(page.video.path())
    # ---------------------
    context.close()
    browser.close()

with sync_playwright() as playwright:
    run(playwright)

